"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.__esModule = true;
exports.AllExceptionsFilter = void 0;
var common_1 = require("@nestjs/common");
var constants_1 = require("./common/constants");
var utils_1 = require("./common/utils");
var log4js_1 = require("./utils/log4js");
var AllExceptionsFilter = /** @class */ (function () {
    function AllExceptionsFilter() {
    }
    AllExceptionsFilter.prototype["catch"] = function (exception, host) {
        var ctx = host.switchToHttp();
        var response = ctx.getResponse();
        var request = ctx.getRequest();
        var status = exception instanceof common_1.HttpException
            ? exception.getStatus()
            : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
        var logFormat = "Request original url: ".concat(request.originalUrl, "\n    Method: ").concat(request.method, "\n    IP: ").concat(request.ip, "\n    Status code: ").concat(status, "\n    Response: ").concat(exception.toString());
        log4js_1.Logger.error((0, utils_1.getLogStr)(logFormat));
        if (exception['response'] && exception['response'].statusCode == 403) {
            response.status(200).json({
                resultCode: constants_1.ResCode.FORBIDDEN,
                resultMessage: '禁止访问'
            });
        }
        else {
            response.status(200).json({
                resultCode: constants_1.ResCode.ERROR,
                resultMessage: 'system exception',
                exception: exception['response'] || null
            });
        }
    };
    AllExceptionsFilter = __decorate([
        (0, common_1.Catch)()
    ], AllExceptionsFilter);
    return AllExceptionsFilter;
}());
exports.AllExceptionsFilter = AllExceptionsFilter;
